package com.iyao_app.base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 简单的adapter的封装
 * 作者:  hjb
 * 时间: 2016/2/17.
 */
public abstract class MyBaseAdapterListView<T> extends BaseAdapter {
    public Context context;
    public List<T> data = new ArrayList<>();
    public LayoutInflater mInflater;

    public MyBaseAdapterListView(Context context, List<T> data) {
        super();
        this.context = context;
        if (data != null) {
            this.data = data;
        }
        mInflater = LayoutInflater.from(context);
    }

    public void clear() {
        this.data.clear();
        notifyDataSetChanged();
    }

    public void append(List<T> list) {
        this.data.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public abstract View getView(int position, View convertView, ViewGroup viewGroup);
}
